package sg.edu.nus.iss.billing.service.login;

import sg.edu.nus.iss.billing.common.DbUtil;
import sg.edu.nus.iss.billing.common.Util;
import sg.edu.nus.iss.billing.dao.login.ILoginDAO;
import sg.edu.nus.iss.billing.dao.login.LoginDAO;
import sg.edu.nus.iss.billing.exception.login.UserDoesNotExist;
import sg.edu.nus.iss.billing.vo.customer.AddressVO;
import sg.edu.nus.iss.billing.vo.customer.CustomerComplaintVO;
import sg.edu.nus.iss.billing.vo.customer.CustomerVO;
import sg.edu.nus.iss.billing.vo.login.LoginVO;
import sg.edu.nus.iss.billing.vo.subscription.CableTvVO;
import sg.edu.nus.iss.billing.vo.subscription.SubscriptionVO;

public class LoginMemberServiceImpl implements ILoginMemberService{

	private ILoginDAO loginDAO;
	private UserImpl userImpl;
	private static String logString = "Class LoginMemberServiceImpl : ";
	
	public LoginVO findLoginMemberInfo(String memberId, String password) {
		return loginDAO.getLoginMemberInfo(memberId.trim(), password.trim());
	}
	
	public String findLoginMemberRole(String memberId) {
		return loginDAO.getMemberRole(memberId.trim());
	}	
	
	public UserImpl findLoginMemberInfo(LoginVO loginVO) throws UserDoesNotExist, Exception {
		loginDAO = new LoginDAO();
		System.out.println(logString + "findLoginMemberInfo() Entered");
		
		loginDAO.getLoginMemberInfo(loginVO);
		System.out.println(logString + "findLoginMemberInfo() DAO Called Role is "+ loginVO.getUserRole());
			
		if(loginVO.getUserRole()==null)
					throw new UserDoesNotExist("User "+loginVO.getUserID() +" Does Not Exists");
		
		if(loginVO.getUserRole().equals("agent"))
			userImpl  = new CallAgent(loginVO);
		else if(loginVO.getUserRole().equals("admin"))
			userImpl  = new Administrator(loginVO);
		
	
		return userImpl;
				
	}
	
	public static void main(String[] a){
		LoginMemberServiceImpl l = new LoginMemberServiceImpl();
		try {
		//LoginVO lv = new LoginVO("vipul","password");
		LoginVO lv = new LoginVO("vipuladm","password");
		//CallAgent ca = (CallAgent)l.findLoginMemberInfo(lv);
		Administrator ca = (Administrator)l.findLoginMemberInfo(lv);
//		CustomerVO cvo = ca.viewCustomerDetailsByNRIC("S1234567A");
//		CustomerComplaintVO ccvo = new CustomerComplaintVO();
//		ccvo.setAccountNo(cvo.getAccountId());
//		ccvo.setComplaint("Allammma .. what do u do?");
//		ca.logCustomerComplaint(ccvo);
		
		CustomerVO custVO = new CustomerVO();
		custVO.setContactNo("90171970");
		custVO.setCustomerNme("VIPUL");
		custVO.setEmailTxt("v@c.com");
		custVO.setInterest("MY INTEREST VARIES");
		custVO.setNric("S9988999K");
		AddressVO avo = new AddressVO();
		avo.setLine1("LINE 1");
		avo.setLine2("LINE 2");
		avo.setCity("Jurong");
		avo.setPostalCode("541252");
		custVO.setAddress(avo);
		ca.registerCustomer(custVO);
		CableTvVO cvo = new CableTvVO();
	
		
		/*
		 * 		StringBuilder sb = new StringBuilder();
		sb.append(getAccNo());
		sb.append(DbUtil.DELIMITER);
		sb.append(getSubsId());
		sb.append(DbUtil.DELIMITER);
		sb.append(getName());
		sb.append(DbUtil.DELIMITER);
		sb.append(Util.getFormattedDate(getStartDate()));
		sb.append(DbUtil.DELIMITER);
		sb.append(Util.getFormattedDate(getEndDate()));
		sb.append(DbUtil.DELIMITER);
		sb.append(getStatus());
		return sb.toString();
		 */
		
		} catch (UserDoesNotExist e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
}
